<?php


namespace App\Admin\Controllers;

use SmallRuralDog\Admin\Components\Grid\Tag;
use SmallRuralDog\Admin\Controllers\AdminController;
use SmallRuralDog\Admin\Grid;
use App\Models\Payment;

class PaymentController extends AdminController
{

    public function grid()
    {
        $grid = new Grid(new Payment());

        $grid->defaultSort('updated_at', 'desc');

        $grid->column('pay_no', "支付单")->width(150)->sortable();

        $grid->column('order_bn', "订单编号")->width(150)->sortable();

        $grid->column('member.nickname', '会员')->width(120);

        $grid->column('type', "类型")->width(100)->align("center")->customValue(function ($row, $value) {
            $source = ['payed'=>'支付', 'refunded'=>'退款'];
            return $source[$value];
        });

        $grid->column('paid_amount', '支付金额')->itemSuffix('元')->width(150);
        $grid->column('discount_amount', '优惠金额')->itemSuffix('元')->width(150);
        $grid->column('payment_code_name', '支付方式')->width(100);


        $grid->column('status', "状态")->width(100)->align("center")->customValue(function ($row, $value) {
            $status = ['ready'=>'支付中', 'success'=>'执行成功', 'fail'=>'执行失败'];
            return $status[$value];
        })->component(Tag::make()->type(["ready"=>"default", "执行成功" => "success", "执行失败" => "danger"]));


        $grid->column('remark', '备注');

        $grid->column('created_at', '创建时间')->width(150)->sortable();
        $grid->column('updated_at', '支付时间')->width(150)->sortable();

        // 快速搜索
        $grid->quickSearch(['order_bn' ,'pay_no']);

        $grid->quickSearchPlaceholder("请输入订单号,支付单号");

        $grid->actionLabel(''); // 隐藏操作

        $grid->actions(function (Grid\Actions $actions){

            $actions->hideDeleteAction(); // 隐藏删除操作
            $actions->hideEditAction(); // 隐藏编辑操作

        })->toolbars(function (Grid\Toolbars $toolbars)
        {
            $toolbars->hideCreateButton();
        });

        return $grid;
    }

}
